/*
*
* 扇形区域的缓冲区绘制
* fun_n: 切割细度
* r: 半径
* oriang: 初始角度
* ang: 角度
*
 */

function Fun_bufferInit(gl, fan_n=45, r = 1, oriang = 45, ang = 90) {

    //创建位置
    var positions = [0, 0, -r / 2];

    var angle = oriang * (Math.PI / 180);   //角度
    var step = ang / fan_n * (Math.PI / 180);    //步长

    for (var i = 0; i <= fan_n; i++) {
        const newTria = [
            r * Math.cos(angle),
            0,
            r * Math.sin(angle) - r / 2,
        ];
        positions = positions.concat(newTria);
        angle += step;
    }

    const positionBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

    //创建颜色
    const fancolors = [
        0.4, 0.7, 0.2, 1.0,
    ];

    var faceColors = [];

    for (var i = 0; i <= fan_n + 1; i++) {
        faceColors = faceColors.concat(fancolors);
    }

    const colorBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, colorBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(faceColors), gl.STATIC_DRAW);

    //创建面单元
    var surfaces = [];

    for (var i = 0; i <= fan_n + 1; i++) {
        surfaces.push(i)
    }

    const surfaceBuf = gl.createBuffer();
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, surfaceBuf);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(surfaces), gl.STATIC_DRAW);

    return {
        position: positionBuf,
        color: colorBuf,
        surface: surfaceBuf,
        drawmode: gl.TRIANGLE_FAN,
        drawcount: fan_n + 2,
        transparent: false,
    };
}